package org.mxp.job;

import lombok.extern.slf4j.Slf4j;
import org.mxp.service.TableMessageService;
import org.mxp.utils.TableMessageUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

@Slf4j
@Component
public class Job {
    private boolean isFirst = true;
    @Value("${system.job.open}")
    private boolean systemJobOpen;
    @Autowired
    private TableMessageService tableMessageService;
    @Autowired
    private TableMessageUtil tableMessageUtil;
    @Scheduled(cron="0 0/30 * * * ?")
    public void addTableMessage() {
        if (systemJobOpen) {
            if (!isFirst) {
                log.info("执行表格消息入库任务...");
                tableMessageService.add(tableMessageUtil.getAllCell());
            } else {
                isFirst = false;
            }
        }
    }
}
